<template>
    <div class="container-common score-list">
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item>查看成绩</el-breadcrumb-item>
            <el-breadcrumb-item>查看成绩</el-breadcrumb-item>
        </el-breadcrumb>
        <p>总成绩：{{totalScore}}</p>
        <el-table
                :data="tableData"
                border
                style="width: 100%">
            <el-table-column prop="name" label="名称"></el-table-column>
            <el-table-column prop="score" label="得分"></el-table-column>
        </el-table>
    </div>
</template>

<script>
    import Api from '@utils/api';
    import { mapGetters } from 'vuex';

    export default {
        name: "list",
        data () {
            return {
                tableData: [],
                colList: [],
                totalScore: ''
            }
        },
        computed: {
            ...mapGetters([
                'getCurrentCourseId',
                'getUserId'
            ])
        },
        methods: {
            getTableData () {
                Api({
                    method: 'post',
                    url: '/getScore',
                    params: {
                        course_id: this.getCurrentCourseId,
                        user_id: this.getUserId
                    }
                }).then(res => {
                    if (res.data && res.data.data) {
                        let col = res.data.data.col;
                        let keys = Object.keys(col);
                        let data = res.data.data.student.tasks[0];

                        this.tableData = keys.map(item => {
                            return {
                                id: item || '',
                                name: col[item] || '',
                                score: data[item] || ''
                            }
                        });

                        this.totalScore = res.data.data.student.score;
                    }
                })
            }
        },
        created () {
            this.getTableData();
        }
    }
</script>